package ppu

type ScrollRegister struct {
	ScrollX uint8
	ScrollY uint8
	Latch   bool
}

// NewScrollRegister creates a new ScrollRegister
func NewScrollRegister() *ScrollRegister {
	return &ScrollRegister{
		ScrollX: 0,
		ScrollY: 0,
		Latch:   false,
	}
}

// Write writes to the scroll register
func (s *ScrollRegister) Write(data uint8) {
	if s.Latch {
		s.ScrollY = data
	} else {
		s.ScrollX = data
	}
	s.Latch = !s.Latch
}

// ResetLatch resets the latch
func (s *ScrollRegister) ResetLatch() {
	s.Latch = false
}
